package jihe.collection;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;

/**
 * Created by leiylong on 2020/5/30
 */
public class List {

    /**
    * 底层数据结构是数组，增删慢，查询快，线程不安全,可重复
    */
    @Test
    public void arrayList(){


        ArrayList<String> list= new ArrayList<String>();
        list.add("new");
        list.add("objiect");
        list.add("new");
        //迭代器遍历
        System.out.println("//迭代器遍历");
        Iterator iterator=list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
        //增强for循环遍历
        System.out.println("//增强for循环遍历");
        for (Object object:list){
            System.out.println(object);
        }
        //普通for循环
        System.out.println("//普通for循环");

        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }

    }
    /**
     * 底层数据结构是数组，增删慢，查询快，线程安全,可重复
     */
    @Test
    public void vector(){
        Vector<String> vector=new Vector<String>();
        vector.add("new1");
        vector.add("new");
        vector.add("new");

        Iterator iterator=vector.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }
    /**
     * 底层数据结构是链表，增删慢，查询快，线程不安全,可重复
     */
    @Test
    public void linkedList(){

        LinkedList linkedList=new LinkedList();
        linkedList.add("new");
        linkedList.add(12);
        linkedList.add("new");
        Iterator iterator=linkedList.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }


}
